package org.robustcoupe.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class AsyncerDecorator extends AbstractFluentTask {
  @SuppressWarnings("unused")
  private static final Log LOG = LogFactory.getLog(AsyncerDecorator.class);
  private static AsyncerManager manager = null;
  private Task task;
  private TaskEvent event;
  
  static {
    manager = new AsyncerManager();
    manager.init();
  }

  public AsyncerDecorator(Task task) {
    this.task = task;
  }

  public Task getTask() {
    return task;
  }

  public TaskEvent getEvent() {
    return event;
  }

  public TaskResultType execute() {
    manager.add(task, event);
    return TaskResultType.DELEGATION;
  }

  public AsyncerDecorator event(TaskEvent event) {
    this.event = event;
    return this;
  }
  
  public static void shutdown() {
    manager.shutdown();
  }
}